package fr.inserm.u915.tabixserver;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class EncodingFilter implements Filter
		{
		@SuppressWarnings("unused")
		private FilterConfig cfg;
		
		@Override
		public void init(FilterConfig cfg) throws ServletException
			{
			this.cfg=cfg;
			}
		
		@Override
		public void destroy()
			{
			this.cfg=null;
			}
	
		@Override
		public void doFilter(
				ServletRequest req, ServletResponse res,
				FilterChain chain) throws IOException, ServletException
			{
			String encoding=req.getCharacterEncoding();
			if(encoding==null) encoding="UTF-8";
			res.setCharacterEncoding(encoding);
			}
	
		}
